home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / VBASIC / MCSECURE.ZIP / MCSECURE.BAS < prev    next >
Encoding:
BASIC Source File  |  1996-08-25  |  6.1 KB  |  234 lines

  1. Attribute VB_Name = "SECURITY_bas"
  2. Option Explicit
  3.  
  4. Public Const ApplicationName = "MC-SECURITY"
  5.  
  6. Public DirectoryForApplication      As String
  7. Public SelectedLanguage             As String
  8. Public CurrentLanguage              As Integer
  9. Public SaveTitleForm                As String
  10.  
  11. Public FileToUse                    As String
  12.  
  13. Public SERIALDATA                   As tagSERIALDATA
  14.  
  15.  
  16. Sub FileProcessAdd()
  17.  
  18.    Dim ErrCode          As Integer
  19.    Dim WasSerial        As Integer
  20.  
  21.    ' get the full name to use
  22.    FileToUse = GetFileToUse()
  23.  
  24.    ' if no file selected, stop
  25.    If (Len(FileToUse) = 0) Then Exit Sub
  26.  
  27.    ' check if file is serialized
  28.    WasSerial = cIsSerial(FileToUse)
  29.  
  30.    ' format the serial number field
  31.    frmSerialization.SerNumber.Text = Val(frmSerialization.SerNumber.Text)
  32.  
  33.    ' set the serialization info from fields
  34.    SERIALDATA.Description1 = frmSerialization.SerPart1.Text
  35.    SERIALDATA.Description2 = frmSerialization.SerPart2.Text
  36.    SERIALDATA.Number = frmSerialization.SerNumber.Text
  37.    ' put the serialization info
  38.    ErrCode = cSerialPut(FileToUse, SERIALDATA)
  39.    
  40.    ' check if file was been serialized
  41.    Select Case WasSerial
  42.       Case True
  43.          ' no, display the message
  44.          Call MessageDisplay("3", FileToUse)
  45.       Case False
  46.          ' yes, display the message
  47.          Call MessageDisplay("2", FileToUse)
  48.       Case Else
  49.          ' error
  50.          Call MessageDisplay("6", FileToUse)
  51.    End Select
  52.  
  53. End Sub
  54.  
  55. Sub FileProcessChange()
  56.  
  57.    Dim ErrCode          As Integer
  58.  
  59.    ' get the full name to use
  60.    FileToUse = GetFileToUse()
  61.  
  62.    ' if no file selected, stop
  63.    If (Len(FileToUse) = 0) Then Exit Sub
  64.  
  65.    ' check if file is serialized
  66.    If (cIsSerial(FileToUse) = 0) Then
  67.       ' no, display error
  68.       Call MessageDisplay("1", FileToUse)
  69.  
  70.    Else
  71.       ' yes, add 1 to serial number
  72.       ErrCode = cSerialInc(FileToUse, 1)
  73.       ' read the serialization info
  74.       ErrCode = cSerialGet(FileToUse, SERIALDATA)
  75.       ' set the serialization info on fields
  76.       frmSerialization.SerPart1.Text = SERIALDATA.Description1
  77.       frmSerialization.SerPart2.Text = SERIALDATA.Description2
  78.       frmSerialization.SerNumber.Text = SERIALDATA.Number
  79.       ' check the serial number, for example MOD 10
  80.       If ((SERIALDATA.Number Mod 10) = 0) Then
  81.          ' yes, modulo 10, display message
  82.          Call MessageDisplay("4", FileToUse)
  83.       End If
  84.  
  85.    End If
  86.  
  87. End Sub
  88.  
  89. Sub FileProcessRead()
  90.  
  91.    Dim ErrCode          As Integer
  92.  
  93.    ' get the full name to use
  94.    FileToUse = GetFileToUse()
  95.  
  96.    ' if no file selected, stop
  97.    If (Len(FileToUse) = 0) Then Exit Sub
  98.  
  99.    ' check if file is serialized
  100.    If (cIsSerial(FileToUse) = 0) Then
  101.       ' no, display error
  102.       Call MessageDisplay("1", FileToUse)
  103.  
  104.    Else
  105.       ' yes, display the serialization info
  106.       ErrCode = cSerialGet(FileToUse, SERIALDATA)
  107.       ' set the serialization info on fields
  108.       frmSerialization.SerPart1.Text = SERIALDATA.Description1
  109.       frmSerialization.SerPart2.Text = SERIALDATA.Description2
  110.       frmSerialization.SerNumber.Text = SERIALDATA.Number
  111.  
  112.    End If
  113.  
  114. End Sub
  115.  
  116. Sub FileProcessRemove()
  117.  
  118.    Dim ErrCode          As Integer
  119.  
  120.    ' get the full name to use
  121.    FileToUse = GetFileToUse()
  122.  
  123.    ' if no file selected, stop
  124.    If (Len(FileToUse) = 0) Then Exit Sub
  125.  
  126.    ' check if file is serialized
  127.    If (cIsSerial(FileToUse) = 0) Then
  128.       ' no, display error
  129.       Call MessageDisplay("1", FileToUse)
  130.  
  131.    Else
  132.       ' yes, remove the serialization info
  133.       ErrCode = cSerialRmv(FileToUse)
  134.       ' display remove message
  135.       Call MessageDisplay("5", FileToUse)
  136.  
  137.    End If
  138.  
  139. End Sub
  140.  
  141. Function GetFileToUse() As String
  142.  
  143.    ' check if a file has been selected
  144.    If (frmSerialization.File1.ListIndex >= 0) Then
  145.       ' yes, form the full name
  146.       GetFileToUse = frmSerialization.File1.Path + "\" + frmSerialization.File1.List(frmSerialization.File1.ListIndex)
  147.  
  148.    Else
  149.  
  150.       Call MessageDisplay("0", "")
  151.       
  152.       ' no, return empty
  153.       GetFileToUse = ""
  154.  
  155.    End If
  156.  
  157. End Function
  158.  
  159. Sub Loader()
  160.  
  161.    DoEvents
  162.    
  163.    ' some initializations
  164.    DirectoryForApplication = App.Path + "\"
  165.  
  166.    ' save the caption of this form
  167.    SaveTitleForm = frmSerialization.Caption
  168.    
  169. End Sub
  170.  
  171. Sub MessageDisplay(TextOrder As String, InsertText As String)
  172.  
  173.    ' display a multi-language message box, message are centered
  174.    ' and a timeout of 30 seconds is displayed.
  175.    MsgBox ReadText(TextOrder, InsertText), vbOKOnly, SaveTitleForm
  176.    
  177.    frmSerialization.ZOrder 0
  178.  
  179. End Sub
  180.  
  181. Function ReadText(TextOrder As String, InsertText As String) As String
  182.  
  183.    Dim i                As Integer
  184.    Dim n                As Integer
  185.    Dim Tmp              As String
  186.    Dim BasisText        As String
  187.    
  188.    Select Case TextOrder
  189.       Case "0": BasisText = "You must select a file !"
  190.       Case "1": BasisText = "File '~' is not a serialized file !"
  191.       Case "2": BasisText = "File '~' is now serialized."
  192.       Case "3": BasisText = "File '~' was serialized.ººSerialization has been updated."
  193.       Case "4": BasisText = "Message sample.ººYou've tried this program more than 10 uses.ººRegister this program.ººMessage sample."
  194.       Case "5": BasisText = "Serialization information on file '~' has been removed."
  195.       Case "6": BasisText = "Error when accessing the file '~'."
  196.    End Select
  197.  
  198.    ' insert some text if any
  199.    n = InStr(BasisText, "~")
  200.    If (n > 0) Then
  201.       Tmp = Left$(BasisText, n - 1) + InsertText + Mid$(BasisText, n + 1)
  202.    Else
  203.       Tmp = BasisText
  204.    End If
  205.  
  206.    ' change all º to make a CR
  207.    n = 0
  208.    n = InStr(n + 1, Tmp, "º")
  209.    Do While (n > 0)
  210.       Mid$(Tmp, n, 1) = vbCr
  211.       n = InStr(n + 1, Tmp, "º")
  212.    Loop
  213.  
  214.    ReadText = Tmp
  215.  
  216. End Function
  217.  
  218.  
  219. Public Function RemoveNull(sStr As String) As String
  220.  
  221.    Dim i       As Integer
  222.    Dim n       As Integer
  223.    Dim s       As String
  224.    
  225.    s = sStr
  226.    n = Len(s)
  227.    For i = 1 To n
  228.       If (Asc(Mid$(s, i, 1)) = 0) Then Mid$(s, i, 1) = " "
  229.    Next i
  230.    
  231.    RemoveNull = s
  232.    
  233. End Function
  234.